<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="@/assets/buy.png" alt="">
        <span>超市订单管理系统</span>
      </div>
      <div>
        <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
        <el-button type="success" size="small" @click="logout">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏区域 -->
      <el-aside :width="isCollapse ? '64px' :'200px'">
        <!-- 折叠区域 -->
        <div class="toggle-button" @click="toggleCollapse">
          <i class="el-icon-menu"></i>
        </div>
        <el-menu
          :default-active="activePath"
          :router="true"
          :collapse-transition="false"
          :collapse="isCollapse"
          text-color="#333"
          background-color="#f5f0f0"
          active-text-color="#4880ca">

            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item-group>
                <template slot="title">订单</template>                
                <el-menu-item index="/ListShow" @click="saceNavState('/ListShow')"><i class="el-icon-menu"></i>订单搜索</el-menu-item>
                <el-menu-item index="/List" @click="saceNavState('/List')"><i class="el-icon-menu"></i>订单操作</el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- <el-menu-item index="/order" @click="saceNavState('/order')">
              <i class="el-icon-s-shop"></i>
              <span slot="title">订单管理</span>
            </el-menu-item> -->

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-home"></i>
                <span>供应商管理</span>
              </template>
              <el-menu-item-group>
                <template slot="title">供应商</template>
                <el-menu-item index="/supplier" @click="saceNavState('/supplier')"><i class="el-icon-menu"></i>供应商搜索</el-menu-item>
                <el-menu-item index="1-2"><i class="el-icon-menu"></i>供应商管理</el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- <el-menu-item index="/supplier" @click="saceNavState('/supplier')">
              <i class="el-icon-s-home"></i>
              <span slot="title">供应商管理</span>
            </el-menu-item> -->

            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-custom"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item-group>
                <template slot="title">用户</template>
                <el-menu-item index="/user" @click="saceNavState('/user')"><i class="el-icon-menu"></i>用户搜索</el-menu-item>
                <el-menu-item index="1-2"><i class="el-icon-menu"></i>用户管理</el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <!-- <el-menu-item index="/user" @click="saceNavState('/user')">
              <i class="el-icon-s-custom"></i>
              <span slot="title">用户管理</span>
            </el-menu-item> -->

            <el-menu-item index="/modify" @click="saceNavState('/modify')">
              <i class="el-icon-s-tools"></i>
              <span slot="title">密码修改</span>
            </el-menu-item>
            <el-menu-item index="/login">
              <i class="el-icon-warning"></i>
              <span slot="title">退出系统</span>
            </el-menu-item>
        </el-menu>
      </el-aside>
        <!-- 主题区域 -->
        <el-container>
          <!-- 内容区域 -->
          <el-main>
            <!-- 路由占位符 -->
            <router-view></router-view>
          </el-main>
        </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name:'Home',
  components:{
    
  },
  // 被创建时
  created(){
    // this.getMenuList()
    this.activePath=window.sessionStorage.getItem('activePath')
  },
  data(){
    return{
      // 左侧菜单中
      // menlist:[]
      // 是否折叠
      isCollapse:false,
      // 被激活的地址
      activePath:'',
    }
  },
  methods:{
    logout(){
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 点击折叠导航栏
    toggleCollapse(){
      this.isCollapse=!this.isCollapse
    },
    // 保存链接的激活状态
    saceNavState(activePath){
      window.sessionStorage.setItem('activePath',activePath)
      this.activePath=activePath
    }
    // 获取所有的菜单
    // async getMenuList(){
    //   const {data:res} =await this.$http.get('menus')
    //   if(res.meta.status!==200) return this.$message.error(res.meta.msg)
    //   this.menulist=res.data
    //   console.log(res);
    // }
  },
}
</script>

<style lang="less" scoped>
  .el-avatar{
    margin-right: 20px;
  }
  .home-container{
    height: 100%;
  }
  .el-header{
    // background-color: #152f41fe;
    background: linear-gradient(to bottom,#60acf0,#64a5df,#62a0dd,#5994d6,#4f8ace,#4880ca);
    background:-webkit-linear-gradient(to bottom,#60acf0,#64a5df,#62a0dd,#5994d6,#4f8ace,#4880ca);
    background:-moz-linear-gradient(to bottom,#60acf0,#64a5df,#62a0dd,#5994d6,#4f8ace,#4880ca);
    background:-ms-linear-gradient(to bottom,#60acf0,#64a5df,#62a0dd,#5994d6,#4f8ace,#4880ca);
    display: flex;
    // 两边对齐
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 22px; 
    >div{
      display: flex;
      align-items: center;
      >span{
        margin-left: 2px;
        text-shadow: 2px 1px #000;
        font-weight: 700;
      }
    }
  }
  .el-aside{
    background-color: #f5f0f0;
    border-radius:10px 10px 0 0;
    .el-menu{
    font-weight: 700;
    font-size: 15px;
    border-right: none;
  }
  }
  .el-main{
    background-color: rgb(255, 250, 250);
  }
  .toggle-button{
    background-color: #60acf0;
    height: 30px;
    font-size: 20px;
    line-height: 30px;
    text-align: center;
    color: #fff;
    cursor: pointer;
    border-radius:10px 10px 0 0;
  }
</style>